// 人员管理相关的配置
import axios from "axios";
export default {
  namespaced: true,
  actions: {
    addPersonWang(context,value){
      if(value.name.indexOf('王')===0){
        context.commit('ADD_PERSON',value)
      }else {
        alert('添加的人必须姓王')
      }
    },
    // 发送请求
    addSentence(context){
      axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
          response=>{
            context.commit('ADD_SENTENCE',response.data)
          },
          error=>{
            alert(error.message)
          }
      )
    }
  },
  mutations: {
    ADD_PERSON(state, value) {
      console.log('ADD_PERSON,value-----', value)
      state.personList.unshift(value)
    },
    ADD_SENTENCE(state,value){
      state.sentence=value
    }
  },
  state: {
    personList: [{
      id: 0,
      name: '张三'
    }],
    sentence:''
  },
  getters: {
    firstPersonName(state){
      return state.personList[0].name
    }
  }
}